package com.jbit.hxy.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jbit.hxy.common.Result;
import com.jbit.hxy.feign.MenuFeignClient;
import com.jbit.hxy.mapper.WxShoppingCartMapper;
import com.jbit.hxy.model.po.WxShoppingCart;
import com.jbit.hxy.model.vo.WxDishFlavorVO;
import com.jbit.hxy.model.vo.WxShoppingCartVO;
import com.jbit.hxy.service.order.WxShoppingCartService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
* @author 28575
* @description 针对表【wx_shopping_cart(购物车)】的数据库操作Service实现
* @createDate 2024-09-12 19:43:33
*/
@Service
@RequiredArgsConstructor
public class WxShoppingCartServiceImpl extends ServiceImpl<WxShoppingCartMapper, WxShoppingCart>
    implements WxShoppingCartService {
    private final WxShoppingCartMapper wxShoppingCartMapper;
    private final MenuFeignClient menuFeignClient;

    @Override
    public Result getShoppingCartByUserId(Integer userId) {
        List<WxShoppingCart> wxShoppingCartList = wxShoppingCartMapper.getShoppingCartByUserId(userId);
        if (wxShoppingCartList == null) {
            return Result.fail("暂时没有购物车");

        }
        return Result.success(wxShoppingCartList);
    }

    @Override
    public Result addShoppingCart(WxShoppingCart wxShoppingCart) {
        wxShoppingCart.setCreateTime(LocalDateTime.now());
        wxShoppingCartMapper.insert(wxShoppingCart);
        return Result.success("添加成功");
    }

    @Override
    public Result updateShoppingCart(List<WxShoppingCart> wxShoppingCartList) {
        for (WxShoppingCart wxShoppingCart : wxShoppingCartList) {
            wxShoppingCartMapper.updateById(wxShoppingCart);
        }
        return Result.success("修改成功");
    }

    @Override
    public Result getShoppingCartClear(Integer userId) {

        wxShoppingCartMapper.deleteByUserId(userId);
        return Result.success("清空成功");
    }


}




